<?php

namespace App\Common;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
class JwtToken
{
    private static $instance;

    private function __construct(){


    }

    private function __clone(){

        // TODO: Implement __clone() method.

    }

    public static function getInstance(){
        if (self::$instance==null){
            self::$instance=new JwtToken();
        }
        return self::$instance;
    }

    public static function createToken($data)
    {
        $key = "example_key";
        $payload = array(
            "iss" => "http://example.org",
            "aud" => "http://example.com",
            "iat" => 1356999524,
            "nbf" => 1357000000,
            'user_id'=>$data
        );
        $jwt = JWT::encode($payload, $key, 'HS256');
        return $jwt;
    }
    //解密
    public static function decodeToken($jwt){
        $key = "example_key";
        $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
        if ($decoded){
            return $decoded;
        }else{
            return  false;
        }

    }


}
